#include "stdafx.h"
#include "Flower.h"
#ifndef _SERVER
#include "./Agent/Funcs.h"
extern DrawFunctions g_drawFunctions;
#endif

CFlower::CFlower(void):
    CSprite()
{
    m_nPollenNum = 0;
    m_size.cx = 0;
    m_size.cy = 0;
    m_CenterPos.x = m_position.x + 50;
    m_CenterPos.y = m_position.y + 20;
    m_nLife = 0;
}

CFlower::CFlower(CPoint& postion):
    CSprite(postion)
{
    m_nPollenNum = 1000;
    m_size.SetSize(134, 177);
    m_CenterPos.x = postion.x + 50;
    m_CenterPos.y = postion.y + 20;
    m_nLife = 15000 + rand() % 15000;
}

CFlower::~CFlower(void)
{
}

#ifndef _SERVER
void CFlower::Draw()
{
    if (g_drawFunctions.DrawFlower)
        g_drawFunctions.DrawFlower(m_position, m_size);
}
#endif

void CFlower::SerializeSubClass(CMarkup& xmlMessage)
{
}

BOOL CFlower::DeSerializeSubClass(CMarkup& xmlMessage)
{
    return TRUE;
}

BOOL CFlower::Consume()
{
    if (m_nPollenNum)
    {
        m_nPollenNum--;
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

INT& CFlower::GetPollenNum()
{
    return m_nPollenNum;
}

CPoint& CFlower::GetCenterPos()
{
    return m_CenterPos;
}

void CFlower::HarvestPollen()
{
    if (m_nLife && m_nPollenNum < 500)
    {
        m_nPollenNum += rand() % 1000;
        m_nLife--;
    }
}

BOOL CFlower::IsDie()
{
    return ((m_nLife == 0) ? TRUE : FALSE);
}
